<?php

class SchemaGenerator
{
	private $dao;
	private $databaseGenerator;
	
	public $debug = false;
	
	public function __construct($path,$server,$database,$username,$password)
	{
		$this->databaseGenerator = new DatabaseGenerator($path,$database);
		$this->dao = new Dao($server,$database,$username,$password);
	}
	
	public function build()
	{
		$drops = $this->databaseGenerator->generateDrop();
		$creates = $this->databaseGenerator->generateCreate();
		
		if(sizeof($drops) != sizeof($creates))
			throw new Exception("Size of Create and Drop Statements is not equal.");
		
		
		$sql = new SqlStatement();
		for($i=0;$i<sizeof($drops);$i++)
		{
			if($this->debug)
				echo $drops[$i];
			$sql->setSQL($drops[$i]);
			$this->dao->execute($sql);
			
			if($this->debug)
				echo $creates[$i];
			$sql->setSQL($creates[$i]);
			$this->dao->execute($sql);
		}		
	}
}

?>